package com.yun.algorithmproblem.leetcode;

public class Leetcode299 {

    /*
        实际上2个循环可以合并在一起.****
     */
    public String getHint(String secret, String guess) {
        int bulls = 0, cows = 0;
        int[][] counts=new int[10][1000];
        int[][] cowsCount=new int[10][2];
        char[] secretChar = secret.toCharArray();
        char[] guessChar = guess.toCharArray();
        for (int i = 0; i < secretChar.length; i++) {
            char sc=secretChar[i];
            counts[sc-'0'][i]++;
            cowsCount[sc-'0'][0]++;
        }
        for (int i = 0; i < guessChar.length; i++) {
            char gc=guessChar[i];
            if(counts[gc-'0'][i]==1){
                bulls++;
                cowsCount[gc-'0'][0]--;
            }else {
                cowsCount[gc-'0'][1]++;
            }
        }
        for (int[] c : cowsCount) {
            cows+=Math.min(c[0],c[1]);
        }
        return new String(bulls+"A"+cows+"B");
    }

    public static void main(String[] args) {
        String secret="1807",guess="7810";
        Leetcode299 obj=new Leetcode299();
        System.out.println(obj.getHint(secret,guess));
    }
}
